package org.example.innovate.config;

import org.codehaus.jettison.json.JSONException;
import org.example.innovate.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class ScheduledTasks {

    private final DishService dishService;

    @Autowired
    public ScheduledTasks(DishService dishService) {
        this.dishService = dishService;
    }

    @Scheduled(fixedRate = 60000) // 每隔60秒执行一次
    public void executeUpdateDataTask() throws JSONException, IOException {
        dishService.updateData();
    }

    @Scheduled(cron = "0 0 2 * * ?")
    public void executeAnotherTask() throws JSONException, IOException {
        dishService.updateUser();
    }
}
